<template>
  <div class="w_h_100">

    <div class="box search" ref="searchRef">
      <div class="inlet">待办任务 > 待推客户 > <span class="size">融资批量</span></div>
      <myform :fields="fields1" :model="values" class="m_t_10" :options="options" v-if="!isExpand">
      </myform>
      <myform :fields="fields" :model="values" @handleSelect="handleSelect" class="m_t_10" :options="options"
        v-if="!isExpand">
      </myform>
      <div class="d_f j_c_s_b" v-if="!isExpand">
        <span></span>
        <div class="btn d_f a_i_c">
          <el-button @click="resetting">重置</el-button>
          <el-button type="primary" :icon="Search" @click="searchFor">搜索</el-button>
          <span class="expand d_f a_i_c" @click="screen(true)">收起筛选 <img src="../../../assets/up.png" alt=""
              class="m_l_5"></span>
        </div>
      </div>
      <div v-if="isExpand" class="d_f j_c_s_b m_t_10">
        <myform :fields="fields1" :model="values" class="" :options="options">
        </myform>
        <div class="btn d_f a_i_c">
          <el-button @click="resetting">重置</el-button>
          <el-button type="primary" :icon="Search" @click="searchFor">搜索</el-button>
          <span class="expand d_f a_i_c" @click="screen(false)">展开筛选 <img src="../../../assets/below.png" alt=""
              class="m_l_5"></span>
        </div>
      </div>
    </div>
    <div class="mytable m_t_10 " :style="{ height: `calc(100% - ${height})` }">
      <div class="d_f j_c_s_b a_i_c">
        <h4>批次列表</h4>
        <div>
          <el-button plain type="primary" @click="dialogVisible1 = true"
            v-hasPerm="'financingEnterInfo'">单笔信息录入</el-button>
          <el-button plain type="primary" @click="dialogVisible = true"
            v-hasPerm="'financingImportInfo'">批次客户信息表导入</el-button>
          <el-button type="primary" @click="openDialog" :disabled="selection.length > 0 ? false : true"
            v-hasPerm="'submissionFinancing'">批次提交</el-button>
          <el-button plain type="danger" @click="batchDeletion" :disabled="selection.length > 0 ? false : true"
            v-hasPerm="'deleteFinancing'">删除</el-button>
        </div>
      </div>
      <mytable :fields="tableFields" :ergodicData="ergodicData" :isSelection="true" @selecSelection="selecSelection"
        width="110" ref="tableRef" :values="values" api="runTaskWaitingCus" class="m_t_10">
        <template v-slot:timeLimit="{ row }">
          <span>{{ row.timeLimit || '0' }}天</span>
        </template>
        <template v-slot:approveStatus="{ row }">
          <span>{{ row.approveStatus == 1 ? '正常' : '超时' }}</span>
        </template>
        <template v-slot:repaymentMode="{ row }">
          <span v-if="row.repaymentMode == 1">一次性还款</span>
          <span v-if="row.repaymentMode == 2">等额每月</span>
          <span v-if="row.repaymentMode == 3">等额每季</span>
          <span v-if="row.repaymentMode == 4">等额本金</span>
          <span v-if="row.repaymentMode == 5">等额本息</span>
          <span v-if="row.repaymentMode == 6">固定还款日-等额本息</span>
          <span v-if="row.repaymentMode == 7">固定还款日-最后一次还本息</span>
          <span v-if="row.repaymentMode == 8">推算日还款-等额本息</span>
          <span v-if="row.repaymentMode == 9">推算日还款-最后一次还本息</span>
          <span v-if="row.repaymentMode == 10">按银行借款合同执行</span>
          <span v-if="row.repaymentMode == 11">其他</span>
        </template>
        <template v-slot:productName="{ row }">
          <div class="d_f a_i_c">
            <div class="isRead" v-if="row.isRead == 0"></div>
            <div class="noRead" v-else></div>
            {{ row.productName }}
          </div>
        </template>
        <template v-slot:operation="{ row }">
          <div class="d_f j_c_s_b">
            <span class="edit" @click="addInformation(row)" v-hasPerm="'supplementaryInfoFinancing'">补充信息</span>
            <span class="error" @click="deleteOut(row)" v-hasPerm="'deleteFinancing'">删除</span>
          </div>
        </template>
      </mytable>
    </div>
    <!--批次客户信息表导入-->
    <el-dialog v-model="dialogVisible" title="批次客户信息表导入" width="600" :before-close="handleClose">
      <div v-loading="loading" element-loading-text="上传中">
        <myform :fields="fields2" :model="model" ref="batchForm" class="m_t_10" :rules="rules" :options="options"
          @handleSelect="handleSelect">
        </myform>
        <div class="back d_f j_c_c a_i_c" v-if="!model.file">
          <el-upload class="upload-demo" :http-request="handleUpload" :headers="headers" :show-file-list="false" :before-upload="beforeUpload"
             multiple :limit="100000000">
            <el-button type="primary" :icon="Upload" plain>点击上传</el-button>
          </el-upload>
        </div>
        <div class="back d_f  a_i_c " v-else>
          <div class="d_f j_c_s_b w_100 a_i_c">
            <div class="d_f a_i_c " @click="downloadUrl">
              <img src="../../../assets/container.png" alt="" class="container">
              <div class="m_l_20">
                <div class="fileName">{{ model.fileName }}</div>
                <div class="size1">{{ model.size }}</div>
              </div>
            </div>
            <el-upload class="upload-demo" :headers="headers" :show-file-list="false" :before-upload="beforeUpload"
            :http-request="handleUpload"  multiple :limit="100000000">
              <div class="tips">重新上传</div>
            </el-upload>
          </div>
          <div class="w_100 d_f eor a_i_c" v-if="model.state == 1" @click="downloadUrl">
            <img src="../../../assets/error.png" alt="" class="error_icon">
            上传信息有误，点击下载表格进行修改
          </div>
        </div>
        <el-dropdown @command="downloadFile">
          <div class="d_f m_t_20 a_i_c tips c_p">
            <el-icon>
              <Download />
            </el-icon>
            下载批次客户信息表模板表格
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item v-for="(item, index) in list" :command="item.url">{{ item.name }}</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>

      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="batchAdd" v-myRepeat>
            确 认
          </el-button>
        </div>
      </template>
    </el-dialog>
    <!--单笔信息表导入-->
    <el-dialog v-model="dialogVisible1" title="单笔信息表导入" width="600" :before-close="handleClose1">
      <div class="stroke">
        <myform :fields="fields3" ref="form" labelPosition="top" :model="model1" @handleSelect="handleSelect"
          :rules="rules" class="m_t_10" :options="options">
        </myform>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose1">取 消</el-button>
          <el-button type="primary" @click="queryPath" v-myRepeat>
            确 认
          </el-button>
        </div>
      </template>
    </el-dialog>
    <!--单笔信息表导入-->
    <el-dialog v-model="dialogVisible2" title="批次提交" width="600" :before-close="handleClose2">
      <div class="d_f a_i_c">
        客户数量
        <span class="num">{{ selection.length || '0' }}</span>
      </div>
      <div class="d_f a_i_c">
        担保总额
        <span class="num">{{ total || '0' }}</span>
        <span class="unit">元</span>
      </div>
      <div class="batchForm">
        <myform :fields="fields4" ref="form1" labelPosition="top" :model="model2" @handleSelect="handleSelect"
          :rules="rules" class="m_t_10" :options="options">
          <template v-slot:agencyId>
            <el-cascader v-model="model2.agencyList" @change="handleSelect('agencyId')" placeholder="请选择经办机构"
              :options="options.agencyId" :props="agencyProps" />
          </template>
        </myform>
      </div>
      <div v-if="model2.agencyId">
        合作选择：
        <el-radio-group v-model="model2.agencyProductId">
          <el-radio v-for="(item, index) in options.agencyProductId" @change="getagencyDetail(model2.agencyProductId)"
            :value="item.id">合作{{ index + 1
            }}</el-radio>
        </el-radio-group>
      </div>
      <div class="incoming_form" v-if="model2.agencyId">
        <myform :fields="fields5" ref="cooperateForm" :options="options" :model="model2.agencyData" :rules="rules"
          labelPosition="top" class="m_t_16">
        </myform>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose2">取 消</el-button>
          <el-button type="primary" @click="submission" v-myRepeat>
            确 认
          </el-button>
        </div>
      </template>
    </el-dialog>
    <component class="m_t_20" :is="FormComponents['ryfp']" v-if="taskId" :isEnabled="1" ref="ryfp" type="useForm"
    @resultData="resultData" />
  </div>
</template>
<script lang='ts'>
import { defineComponent, reactive, toRefs, onBeforeMount, ref } from 'vue'
import { Search, EditPen } from '@element-plus/icons-vue'
import { copy, fileFormat, formatFileSize, addNumbers, objectMatching } from '../../../utils/date'
import { useRouter } from 'vue-router'
import { deptList } from '../../../api/system/authority'
import { Message } from '../../../utils/resetMessage'
import { ElMessageBox } from 'element-plus'
import { financingType } from '../../../type/agent'
import { Upload, Download } from '@element-plus/icons-vue'
import { httpConfig } from '../../../utils/config'
import { projectBatchAdd, fileListByPage, projectBatchCommit, projectInputDel,batchAssign } from '../../../api/agent'
import { projectInput, agencyProjectList, agencyProjectDetail } from '../../../api/business'
import { cooperativeAgencyListAll } from '../../../api/system/flowPath'
import { FormComponents } from '../../../components/formChildren/myComponents'
import axios from 'axios'
const values = {
  findKey: '',//项目搜索
  agencyProjectId: '',//合作机构
  deptId: '',//业务部门
  startTime: '',//开始时间
  endTime: '',//结束时间
  range: [],
  province: '',
  city: '',
  county: '',
  category: 2
}
const model = {
  type: '',
  file: '',
  fileName: '',
  state: 0,
  size: '0kb',
  customerType: ''
}
const model1 = {
  productType: '',
  id: '',
  cooperativeAgencyId: '',
}
const model2 = {
  agencyId: '',
  deptId: '',
  deptName: '',
  agencyList: [],
  agencyBranchId: '',
  agencyName: '',
  agencyProductId: '',
  agencyBranchName: '',
  agencyData: {
    agencyProductId: '',
    beginDate: '',//起始日期
    finishDate: '',//截止日期
    amountLimit: '',//总额度-合作额度
    spendingLimit: '',//使用额度
    balanceLimit: '',//剩余额度
    liability: '',//分责比例
  }
}
export default defineComponent({
  name: '',
  components: {
    Download
  },
  setup() {
    const data: financingType = reactive({
      fields1: [
        {
          label: "项目搜索",
          prop: 'findKey',
          placeholder: '导入批次/产品名称/证件号',
          type: 'input',
          labelWidth: '70px'
        },
        // {
        //   label: "业务部门",
        //   prop: 'deptId',
        //   placeholder: '请选择',
        //   type: 'select',
        //   labelWidth: '70px',
        //   bindLabel: 'name',
        //   bindValue: 'id',
        // },
      ],
      fields: [


        {
          label: "进件时间",
          prop: 'range',
          placeholder: '请选择',
          type: 'range',
          labelWidth: '70px',
        },
        {
          label: "所在省",
          prop: 'province',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '70px',
          bindLabel: 'name',
          bindValue: 'name',
        },
        {
          label: "所在盟市",
          prop: 'city',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '70px',
          bindLabel: 'name',
          bindValue: 'name',
        },
        {
          label: "所在旗县",
          prop: 'county',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '70px',
          bindLabel: 'name',
          bindValue: 'name',
        },
      ],
      options: {
        agencyProductId: [],
        agencyId: [],
        deptId: [],
        province: [],
        city: [],
        county: [],
        type: [
          {
            name: '融资-自然人',
            id: 1,
            customerType: 1,
          },
          {
            name: '融资-法人',
            id: 2,
            customerType: 2,
          },
          // {
          //   name: '非融资-自然人',
          //   id: 3,
          //   customerType: 1,
          // },
          // {
          //   name: '非融资-法人',
          //   id: 4,
          //   customerType: 2,
          // },
        ],
        productType: [
          {
            name: '融资批量',
            id: 2,
          },

          {
            name: '非融资批量',
            id: 4,
          },
        ],
        id: [],
      },
      values: copy(values),
      isExpand: true,
      tableFields: [
        {
          label: '导入批次',
          prop: 'batchNo',
          width: '250px',
        },
        {
          label: '产品名称',
          prop: 'productName',
          width: '250px',
        },
        {
          label: '证件号',
          prop: 'idCard',
          width: '250px',
        },
        {
          label: '地区',
          prop: 'agencyArea',
          width: '250px',
        },
        {
          label: '担保金额（元）',
          prop: 'totalMoney',
          width: '250px',
        },
        {
          label: '期限（月）',
          prop: 'period',
          width: '150px',
        },
        {
          label: '还款方式',
          prop: 'repaymentMode',
          width: '200px',
        },
        {
          label: '担保费率（%）',
          prop: 'guaranteeRate',
          width: '200px',
        },
        {
          label: '应收保费（元）',
          prop: 'receivablePremium',
          width: '250px',
        },
        {
          label: '提交时间',
          prop: 'createTime',
          width: '250px',
        },
      ],
      areaProps: {
        multiple: false,
        value: 'name',
        label: 'name',
        children: 'districts',
        checkStrictly: true
      },
      districts: [],
      height: '160px',
      dialogVisible: false,
      fields2: [
        {
          label: "上传模版类型",
          prop: 'type',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '110px',
          bindLabel: 'name',
          bindValue: 'id',
        },
      ],
      model: copy(model),
      rules: {
        type: [
          { required: true, message: '请选择上传模版类型', trigger: 'change' },
        ],
        productType: [
          { required: true, message: '请选择业务类型', trigger: 'change' },
        ],
        id: [
          { required: true, message: '请选择产品', trigger: 'change' },
        ],
        agencyId: [
          { required: true, message: '请选择合作机构', trigger: 'change' },
        ],
        deptId: [
          { required: true, message: '请选择受理业务部门', trigger: 'change' },
        ],
        bizType: [
          { required: true, message: '请选择业务性质', trigger: 'blur' },
        ],
        beginDate: [
          { required: true, message: '请选择起始日期', trigger: 'blur' },
        ],
        finishDate: [
          { required: true, message: '请选择截止日期', trigger: 'blur' },
        ],
        amountLimit: [
          { required: true, message: '请输入合作额度', trigger: 'blur' },
        ],
        spendingLimit: [
          { required: true, message: '请输入使用额度', trigger: 'blur' },
        ],
        balanceLimit: [
          { required: true, message: '请输入剩余额度', trigger: 'blur' },
        ],
        liability: [
          { required: true, message: '请输入分责比例', trigger: 'blur' },
        ],
        branchId: [
          { required: true, message: '请选择银行', trigger: 'change' },
        ],
      },
      action: httpConfig.baseURL + '/project_input/batch/file/check',
      headers: {
        token: localStorage.getItem('Token')
      },
      dialogVisible1: false,
      fields3: [
        {
          label: "业务类型",
          prop: 'productType',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '110px',
          bindLabel: 'name',
          bindValue: 'id',
        },
        {
          label: "产品名称",
          prop: 'id',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '110px',
          bindLabel: 'name',
          bindValue: 'id',
        },
      ],
      model1: copy(model1),
      loading: false,
      selection: [],
      dialogVisible2: false,
      total: 0,
      fields4: [
        {
          label: "受理业务部门",
          prop: 'deptId',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '110px',
          bindLabel: 'name',
          bindValue: 'id',
        },
        {
          label: "经办机构",
          prop: 'agencyId',
          placeholder: '请选择',
          type: 'select',
          labelWidth: '110px',
        },
        {
          prop: 'cooperate',
        }
      ],
      model2: copy(model2),
      list: [],
      fields5: [
        {
          label: "起始日期",
          prop: 'beginDate',
          placeholder: '请选择起始日期',
          type: 'date',
          disabled: true,
        },
        {
          label: "截止日期",
          prop: 'finishDate',
          placeholder: '请选择截止日期',
          type: 'date',
          disabled: true,
        },
        {
          label: "合作额度",
          prop: 'amountLimit',
          placeholder: '请输入合作额度',
          type: 'input',
          unit: '元',
          disabled: true,
        },
        {
          label: "使用额度",
          prop: 'spendingLimit',
          placeholder: '请输入使用额度',
          type: 'input',
          unit: '元',
          disabled: true,
        },
        {
          label: "剩余额度",
          prop: 'balanceLimit',
          placeholder: '请输入剩余额度',
          type: 'input',
          unit: "元",
          disabled: true,
        },
        {
          label: "分责比例",
          prop: 'liability',
          placeholder: '请输入分责比例',
          type: 'input',
          unit: "%",
          disabled: true,
        },
      ],
      productId: '',
      agencyProps: {
        multiple: false,
        value: 'id',
        label: 'name',
        children: 'bankIds',
        checkStrictly: true,
      },
      taskId: '',
      ids: [],
    })
    const router = useRouter()
    const tableRef = ref()
    const searchRef = ref()
    const form = ref()
    const form1 = ref()
    const batchForm = ref()
    const ryfp=ref()
    onBeforeMount(() => {
      data.options.province = JSON.parse(localStorage.getItem('districts'))
      methods.getList()
    })
    const methods = {
      //获取选中项
      selecSelection(selection: any) {
        data.selection = selection
      },
      //获取列表数据然后拆分省市区结构
      ergodicData(list) {
        console.log(list);
        // list.map((item: any) => {
        //   if (item.agencyArea) {
        //     let agencyArea = JSON.parse(item.agencyArea)

        //     agencyArea = agencyArea.sort((a, b) => b.length - a.length)
        //     console.log(agencyArea);
        //     item.agencyArea = agencyArea[0].join('/')
        //   }
        // })
        // console.log(list);
        return list
      },
      //获取查询条件数据
      getList() {
        deptList({}).then((res: any) => {
          data.options.deptId = res
        })
        fileListByPage({ itemType: 'CUSTOMER_EXECL', pageNum: 1, pageSize: 10 }).then((res: any) => {
          data.list = res.records
        })

      },
      //是否展开筛选
      screen(flag: boolean) {
        data.isExpand = flag
        data.values = copy(values)
        setTimeout(() => {
          data.height = searchRef.value.offsetHeight + 60 + 'px'
        }, 100)
      },
      //进入详情处理业务
      handle(row: any) {
        router.push({ path: '/agent/singleFinancing/nodeProcessing', query: { id: row.id, projectId: row.projectId, type: 2, flowInstId: row.flowInstId, category: data.values.category } })
      },
      //表格数据重置
      resetting() {
        data.values = copy(values)
        tableRef.value.resettingTable(data.values)
        data.options.city = data.options.county = []
      },
      //搜索
      searchFor() {
        if (data.values.range) {
          if (data.values.range.length > 0) {
            data.values.startTime = data.values.range[0]
            data.values.endTime = data.values.range[1]
          } else {
            data.values.startTime = data.values.endTime = ''
          }
        } else {
          data.values.startTime = data.values.endTime = ''
        }
        tableRef.value.handleCurrentChange(1)
      },
      //根据选择省市区获取相关数据
      handleSelect(prop: string) {
        if (prop == 'province') {
          data.values.city = ''
          data.values.county = ''
          data.options.city = data.options.county = []
          data.options.province.map(item => {
            if (item.name == data.values.province) {
              data.options.city = item.districts
            }
          })
        } else if (prop == 'city') {
          data.values.county = ''
          data.options.city.map(item => {
            if (item.name == data.values.city) {
              data.options.county = item.districts
            }
          })
        } else if (prop == 'type') {
          //选择模版类型区分是自然人还是法人
          data.options.type.map((item: any) => {
            if (item.id == data.model.type) {
              data.model.customerType = item.customerType
            }
          })
        } else if (prop == 'productType') {
          //单笔业务进件获取对应产品
          projectInput({ productType: data.model1.productType }).then((res: any) => {
            data.model1.id = ''
            data.options.id = res
          })
        } else if (data.model1.id == 'id') {
          data.options.id.map((item: any) => {
            if (data.model1.id == item.id) {
              data.model1.cooperativeAgencyId = item.cooperativeAgencyId
            }
          })
        } else if (prop == 'agencyId') {
          data.model2.agencyId = data.model2.agencyList[0]
          if (data.model2.agencyList.length == 2) {
            data.model2.agencyBranchId = data.model2.agencyList[1]
          } else {
            data.model2.agencyBranchId = data.model2.agencyBranchName = ''
          }
          data.options.agencyId.map((item: any) => {
            if (item.id == data.model2.agencyId) {
              data.model2.agencyName = item.name
              item.bankIds.map((item1: any) => {
                if (data.model2.agencyBranchId == item1.id) {
                  data.model2.agencyBranchName = item1.name
                }
              })
            }
          })
          agencyProjectList({ id: data.model2.agencyId, productId: data.productId }).then((res: any) => {
            data.options.agencyProductId = res
            if (res.length > 0) {
              data.model2.agencyProductId = res[0].id
              methods.getagencyDetail(data.model2.agencyProductId)
            }
          })
        } else if (prop == 'deptId') {
          data.options.deptId.map((item: any) => {
            if (item.id == data.model2.deptId) {
              data.model2.deptName = item.name
            }
          })
        }
      },
      //点击合作机构获取机构信息
      getagencyDetail(id) {
        agencyProjectDetail({ id: id, }).then((res: any) => {
          data.model2.agencyData = objectMatching(res, data.model2.agencyData)
        })
      },
      //关闭批次客户信息表导入弹出那个
      handleClose() {
        data.dialogVisible = false
        data.model = copy(model)
      },
      //文件上传之前校验格式
      beforeUpload(file: any) {
        if (!data.model.type) {
          Message({ type: 'error', message: '请选择上传模版类型' })
          return false
        }
        return fileFormat(file, ['xls', 'xlsx',], '格式不正确，只支持xls跟xlsx')
      },
      handleUpload(e: any, file: any){
       console.log(e,file);
       data.loading = true
        let fd = new FormData();
        fd.append("file", e.file)
        fd.append("type", new Blob([JSON.stringify({ "type": data.model.type })], { type: "application/json" }))
        let config = {
          headers: {
            "Content-Type": "multipart/form-data",
            token: localStorage.getItem('Token')
          },
        };
        axios.post(httpConfig.baseURL + '/project_input/batch/file/check', fd, config).then((res: any) => {
          if (res.data.code == '000000') {
            console.log(res,'res');
            data.model.file = res.data.data.fileUrl
            data.model.fileName = e.file.name
            data.model.state = res.data.data.state
            data.model.size = formatFileSize(e.file.size)
            data.loading = false
          } else {
            data.loading = false
            Message({ type: 'error', message: '文件错误，请检查文件' })
          }

        }).catch(err => {
          data.loading = false
        })
      },
      //批次客户信息表导入提交
      batchAdd() {
        batchForm.value.verification().then(() => {
          if (!data.model.file) {
            return Message({ type: 'error', message: '请上传批次客户信息表' })
          }
          if (data.model.state == 1) {
            return Message({ type: 'error', message: '上传信息有误，点击下载表格进行修改' })
          }
          projectBatchAdd({ filePath: data.model.file, productType: data.model.type, customerType: data.model.customerType, type: 2 }).then(() => {
            Message({ type: 'success', message: '提交成功' })
            methods.handleClose()
            methods.searchFor()
          })
        })

      },
      downloadUrl() {
        window.open(data.model.file, '_blank')
      },
      //关闭单笔信息表导入弹窗
      handleClose1() {
        data.dialogVisible1 = false
        data.model1 = copy(model1)
      },
      //关闭单笔信息表导入弹窗
      handleClose2() {
        data.dialogVisible2 = false
        data.model2 = copy(model2)
      },
      //单笔信息录入跳转到业务进件
      queryPath() {
        form.value.verification().then(() => {
          router.push({ path: '/business/incoming', query: { id: data.model1.id, cooperativeAgencyId: data.model1.cooperativeAgencyId, isBatch: 2 } })
        })
      },
      openDialog() {
        if (data.selection.length == 0) return Message({ type: 'error', message: '请选择要操作的数据' })
        let total = 0
        data.selection.map((item: any) => {
          total = addNumbers(total, item.totalMoney)
        })
        let list = data.selection.map((item: any) => {
          return item.productId
        })
        let uniqueArr = Array.from(new Set(list));
        if (uniqueArr.length > 1) return Message({ type: 'error', message: '所选产品不一致' })
        data.total = total.toFixed(2)
        data.productId = uniqueArr[0]
        cooperativeAgencyListAll({ productId: uniqueArr[0] }).then((res: any) => {
          data.options.agencyId = res
          data.dialogVisible2 = true
        })
      },
      //批量下载文件
      downloadFile(e) {
        window.open(e, '_blank')
      },
      //选中列表批次提交
      submission() {
      
        form1.value.verification().then(() => {
          if (Number(data.total) > Number(data.model2.agencyData.balanceLimit)) {
          return Message({ type: 'error', message: '余额不足' })
        }
          let ids = data.selection.map((item: any) => {
            return item.id
          })
          projectBatchCommit({ agencyBranchId: data.model2.agencyBranchId, agencyBranchName: data.model2.agencyBranchName, agencyName: data.model2.agencyName, ids: ids, agencyId: data.model2.agencyId, deptId: data.model2.deptId, deptName: data.model2.deptName, agencyProductId: data.model2.agencyProductId, productId: data.productId, agencyData: data.model2.agencyData }).then((res:any) => {
            Message({ type: 'success', message: '提交成功' })

            methods.searchFor()
            methods.handleClose2()
            tableRef.value.clearSelection()
            data.selection = []
            if (res.length>0) {
              data.ids = res
              data.taskId = res[0]
          } 
          })
        })
      },
      //删除当前批次
      deleteOut(row: any) {
        ElMessageBox.confirm(
          '确定删除当前客户批次？',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
        )
          .then(() => {
            projectInputDel({ ids: [row.id] }).then(() => {
              methods.searchFor()
              Message({ type: 'success', message: '删除成功' })
              tableRef.value.clearSelection()
              data.selection = []
            })
          })
      },
      //批次删除
      batchDeletion() {
        if (data.selection.length == 0) return Message({ type: 'error', message: '请选择要操作的数据' })
        let ids = data.selection.map((item: any) => {
          return item.id
        })
        ElMessageBox.confirm(
          '确定删除所选客户批次？',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
        )
          .then(() => {
            projectInputDel({ ids: ids }).then(() => {
              methods.searchFor()
              Message({ type: 'success', message: '删除成功' })
              tableRef.value.clearSelection()
              data.selection=[]
            })
          })
      },
      addInformation(row: any) {
        router.push({ path: '/business/incoming', query: { id: row.id, isBatch: 1 } })
      },
      resultData(val) {
        batchAssign({ taskIds: data.ids, empId: val.empId }).then(() => {
          Message({ type: 'success', message: '提交成功' })
          ryfp.value.clearValue()
           data.taskId=''
           methods.searchFor()
        })
      }
    }
    return {
      ...toRefs(data),
      Search, EditPen,
      ...methods, tableRef, searchRef, Upload, form, form1, batchForm,FormComponents,ryfp
    }
  }
})
</script>
<style scoped lang='scss'>
.box {
  width: calc(100% - 64px);
  background: #fff;
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  padding: 10px 32px;
  margin-top: 10px;
}

.mytable {
  overflow-y: auto;
  width: calc(100% - 64px);
  background: #fff;
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  padding: 24px 32px;
  height: calc(100% - 200px);
}

.padding {
  padding: 0px 5px;
}

.expand {
  color: #1878FF;
  font-size: 14px;
  margin-left: 8px;
  cursor: pointer;
}

.isRead {
  background: #D54941;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 10px;
}

.noRead {
  width: 8px;
  height: 8px;
  margin-right: 10px;
}

.back {
  width: calc(100% - 40px);
  height: 110px;
  background: rgba(211, 215, 222, 0.2);
  border-radius: 4px;
  padding: 0px 20px;
  position: relative;
}

.fileName {
  color: rgba(0, 0, 0, 0.9);
  font-size: 16px;
  cursor: pointer;
}

.size1 {
  color: rgba(0, 0, 0, 0.4);
  font-size: 11px;
  margin-top: 2px;
  cursor: pointer;
}

.tips {
  color: #1878FF;
}

.container {
  width: 42px;
  height: 42px;
  cursor: pointer;
}

.error_icon {
  width: 15px;
  height: 15px;
}

.eor {
  position: absolute;
  bottom: 5px;
  color: #D54941;
  font-size: 12px;
  cursor: pointer;
}

.num {
  color: #1878FF;
  font-size: 36px;
  font-weight: 700;
  margin-left: 20px;
}

.unit {
  color: #1878FF;
  font-size: 12px;
  margin-top: 20px;
  margin-left: 5px;
}
</style>
<style lang='scss'>
.search {
  .el-form-item {
    margin-bottom: 10px !important;
  }

  .el-input,
  .el-select {
    width: 200px !important;
  }
}

.stroke {
  .el-form-item {
    width: 100% !important;

    .el-select {
      width: 60% !important;
    }
  }
}

.batchForm {
  .el-form-item {
    width: 100% !important;

    .el-select,
    .el-cascader {
      width: 100% !important;

      .el-input {
        width: 100% !important;
      }
    }
  }
}
</style>